<template lang="html">
  <div class="box">
    <header-title :HeaderTitle='title'></header-title>
    <div class="name">
        <label>收货人</label>
        <input type="text" name="name" placeholder="请输入收货人姓名">
    </div>
    <div class="phone">
        <label>联系电话</label>
        <input type="text" name="mobile" placeholder="请输入联系电话">
    </div>
    <div class="lastchild">
        <label>详细地址</label>
        <dizhi :address="addressshuju"></dizhi>
        <textarea placeholder="请输入详细地址" name="xxaddress"></textarea>
    </div>
    <div class="sub_btn">保存地址</div>
  </div>
</template>
<script>
import title from "../header/header.vue";
import dizhi from "./dizhiliandong.vue";
export default {
  data () {
    return {
      title:{
        url:'/gerenaccount',
        title:"编辑收货地址"
      },
      addressshuju:{},

    }
  },
  methods:{
    tijiaoshuju:function(){
      let _url = "/index.php?g=app&m=shopping&a=address_one_post",
      cur_id = window.sessionStorage.getItem("cur_id"),
      sign = window.sessionStorage.getItem("sign"),
      addressid = this.$route.query.id,
      name = document.getElementsByName("name")[0].value,
      mobile = document.getElementsByName("mobile")[0].value,
      sheng = document.getElementsByName("sheng")[0].value,
      shi = document.getElementsByName("shi")[0].value,
      qu = document.getElementsByName("qu")[0].value,
      xxaddress = document.getElementsByName("xxaddress")[0].value,
      conent = this;
      if(!name){
        conent.$toast('收货人姓名不能为空！');
        return false;
      }
      if(!mobile){
        conent.$toast('手机号不能为空！');
        return false;
      }else {
        var reg=/^1[0-9]{10}/;
        if (!reg.test(mobile)) {
          conent.$toast('手机号不正确！');
          return false;
        }
      }
      if(!xxaddress){
        conent.$toast('详细地址不能为空！');
        return false;
      }
      conent.$loading('添加中');
      let _data={
        cur_id:cur_id,
        sign:sign,
        name:name,
        mobile:mobile,
        sheng:sheng,
        shi:shi,
        qu:qu,
        address:xxaddress
      };
      conent.$http.post(_url,_data).then(function(data){
        if(data.data.status== "1"){
          conent.$loading.close();
          conent.$loading('修改成功');
          window.setTimeout(function(){
              conent.$loading.close();
              conent.$router.push({ path: '/gerenaddress' })
          },1500)
        }else {
          conent.$loading.close();
          conent.$toast(data.data.info);
        }
      },function(response){
          conent.$toast(response);
      })
    }
  },
  created:function(){
    let _url = "/index.php?g=app&m=shopping&a=address_one_post",
    cur_id = window.sessionStorage.getItem("cur_id"),
    sign = window.sessionStorage.getItem("sign"),
    addressid = this.$route.query.id,
    name1 = document.getElementsByName("name")[0],
    mobile1 = document.getElementsByName("mobile")[0],
    xxaddress1 = document.getElementsByName("xxaddress")[0],
    conent = this,
    _data = {
      cur_id:cur_id,
      sign:sign,
      id:addressid
    };
    conent.$http.post(_url,_data).then(function(data){
      if(data.data.status== "1"){
        conent.addressshuju = data.data.data.address_info;
        document.getElementsByName("name")[0].value = data.data.data.address_info.name;
        document.getElementsByName("mobile")[0].value = data.data.data.address_info.mobile;
        document.getElementsByName("xxaddress")[0].innerText = data.data.data.address_info.xxaddress;
      }else {
        conent.$toast("还没有收货地址");
      }
    },function(response){
        conent.$toast(response.data);
    })
  },
  components:{
    'header-title':title,
    'dizhi':dizhi
  }
}
</script>

<style scoped lang="less">
@import '../../../assets/less/index.less';
.box {
  .name,.phone,.lastchild{
    font-size: @h1_font_size;
    border-bottom: solid 1px @color8;
    overflow: hidden;
    zoom:1;
    line-height: 10vw;
    font-size: @h1_font_size;
    label{
      display: inline-block;
      width: 20vw;
      height: 10vw;
      float: left;
    }
    input{
      display: inline-block;
      width: 78vw;
      padding: 2vw 0;
    }
    textarea{
      width: 74vw;
      height: 20vw;
      font-size: @h1_font_size;
      line-height: 4vw;
      float: right;
      margin-right: 4vw;
      margin-bottom: 4vw;
    }
  }
  .sub_btn{
    width: @width;
    margin: 0 auto;
    height: 13.3vw;
    line-height: 13.3vw;
    border-radius: 1vw;
    font-size: @h1_font_size;
    color: @color1;
    background-color: @color;
  }
}
</style>